package com.ktjiaoyu.crm;

import com.ktjiaoyu.crm.entity.User;
import com.ktjiaoyu.crm.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class UserMapperTester {

    @Autowired
    private UserMapper userMapper;

    @Test
    public void testInsert() throws Exception {
        userMapper.insert(new User("ktjiaoyu", "123456", 9L, 1));
    }

    @Test
    public void testGet() throws Exception {
        User user = userMapper.get(2L);
        System.out.println("userName :" + user.getUsrname());
    }

    // 测试更新方法
    @Test
    public void testUpdate() throws Exception {
        User user = new User();
        user.setUsrid(2L);
        user.setUsrname("绒花");
        userMapper.update(user);
        User updatedUser = userMapper.get(2L);
        assert updatedUser.getUsrname().equals("绒花");
    }

    // 测试删除方法
    @Test
    public void testDelete() throws Exception {
        long idToDelete = 93L;
        userMapper.delete(idToDelete);
        User deletedUser = userMapper.get(idToDelete);
        assert deletedUser == null;
    }

    // 测试查询所有方法
    @Test
    public void testFindAll() throws Exception {
        List<User> users = userMapper.findAll();
        for (User user : users) {
            System.out.println(user);
        }
    }
}
